package com.weng.cloud.service8881.concurrenct.algorithm.recursion.sample;

import com.weng.cloud.service8881.concurrenct.algorithm.recursion.base.Puzzle;
import com.weng.cloud.service8881.concurrenct.algorithm.recursion.base.PuzzleSample;

/**
 * @Author: weng
 * @Date: 2022/7/10
 * @Description: com.weng.cloud.service8881.concurrenct.algorithm.recursion.sample
 * @see <a href="https://blog.csdn.net/weixin_43638238/article/details/107499223">蓝桥杯 15决赛 B4 穿越雷区(这里使用dfs处理)</a>
 */

public class DfsMazePuzzleSample extends PuzzleSample<Integer, Character> {

    @Override
    protected Character[] prepareData() {
        return new Character[]{
                'A', '+', '-', '+', '-',
                '-', '+', '-', '-', '+',
                '-', '+', '+', '+', '-',
                '+', '-', '+', '-', '+',
                'B', '+', '-', '+', '-'
        };
    }

    @Override
    protected PuzzleSample<Integer, Character> initPuzzle(Character[] moves) {
        int bgnIdx = -1, endIndx = -1;
        for (int i = 0; i < moves.length; i++) {
            switch (moves[i]) {
                case 'A':
                    bgnIdx = i;
                    break;
                case 'B':
                    endIndx = i;
                    break;
            }
        }
        Puzzle<Integer, Character> puzzle = new DfsMazePuzzle(moves, bgnIdx, endIndx, 5);
        this.solver.setPuzzle(puzzle);
        return this;
    }

    @Override
    protected boolean illegalParams() {
        return false;
    }

    @Override
    protected void endHandle() {

    }
}
